package com.jinboe.cms.doc.module;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
/**
 * XML基础对象---对应所有XML对象
 * @author weibey
 *
 */
public class DocModule {
	private String name;
	private String text;
	private List<Map<String,String>> attributeList=new ArrayList();
	private List<DocModule> subElementList=new ArrayList();
	
	/**
	 * 添加子元素对象
	 * @param docModule
	 */
	public void addSubElementList(DocModule docModule){
		subElementList.add(docModule);
	}
	/**
	 * 设置属性值
	 * @param attributeName
	 * @param attributeValue
	 */
	public void addAttribute(String attributeName,String attributeVale){
		String keyName=null;
		Map map=null;
		for(Map<String,String> attributeMap:attributeList){
			Set<String>keySet=attributeMap.keySet();
			Iterator<String>it=keySet.iterator();
			while(it.hasNext()){
				String key=it.next();
				if(attributeName.equalsIgnoreCase(key)){
					keyName=key;
					map=attributeMap;
				}
			}
			
		}
		if(StringUtils.isNotBlank(keyName)){
			map.put(keyName, attributeVale);
		}else{
			map=new HashMap();
			map.put(attributeName, attributeVale);
			attributeList.add(map);
		}
	}
	/**
	 * 设置属性值
	 * @param attributeName
	 * @return
	 */
	public String getAttributeValue(String attributeName){
		for(Map<String,String> map:attributeList){
			Set<String>keySet=map.keySet();
			Iterator<String>it=keySet.iterator();
			while(it.hasNext()){
				String key=it.next();
				if(attributeName.equalsIgnoreCase(key)){
					return map.get(key);
				}
			}
			
		}
		return null;
	}
	
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	public List<Map<String, String>> getAttributeList() {
		return attributeList;
	}
	public void setAttributeList(List<Map<String, String>> attributeList) {
		this.attributeList = attributeList;
	}
	public List<DocModule> getSubElementList() {
		return subElementList;
	}
	public void setSubElementList(List<DocModule> subElementList) {
		this.subElementList = subElementList;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
}
